<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            body {font-size: 12px;}
        </style>
    </head>
    <body>
        <div><a href="?q=merge">合并到style.css</a> | <a href="?q=clear">清空临时样式</a></div>
        <?php
        $q=isset($_GET['q'])?$_GET['q']:'';
        switch ($q){
            case 'merge':
                mergestyle();
                break;
            case 'clear':
                clearstyle();
                break;
        }
        ?>
    </body>
    <?php
    /**
     * 合并样式到style.css
     * @since 1.0.0 2014-2-7
     */
    function mergestyle(){
        if(file_exists('style.css')) unlink ('style.css');
        $rootpath=str_replace("\\", "/", dirname(__FILE__)).'/';
        $styles='// Created on : '.date('Y-m-d H:i:s').' | Author : sutroon'.PHP_EOL;
        $dir=  opendir($rootpath);
        while(($file = readdir($dir)) !== false) {
            if($file == '.' || $file == '..' || $file=='index.php') continue;
            $styles.=file_get_contents($file);
        }
        file_put_contents($rootpath.'style.css', $styles);
        echo '<div>生成成功.<a href="style.css" target="_blank">[查看]</a></div>';
    }
    
    /**
     * 清空临时样式
     * @since 1.0.0 2014-2-7
     */
    function clearstyle(){
        $rootpath=str_replace("\\", "/", dirname(__FILE__)).'/';
        $dir=  opendir($rootpath);
        while(($file = readdir($dir)) !== false) {
            if($file == '.' || $file == '..' || $file=='index.php') continue;
            unlink($file);
        }
        echo '<div>已清空.</div>';
    }
    ?>
</html>
